<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>协同后台管理系统</title>
	<meta name="decorator" content="default"/>
	<link href="${ctxStatic}/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
	<%--<%@include file="/WEB-INF/views/include/treetable.jsp" %>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#treeTable").treeTable({expandLevel : 3});
		});
	</script>--%>

</head>

<body>
<div class="wrapper wrapper-content">
	<div class="row">
		<div class="col-sm-12">
			<div class="ibox float-e-margins">
			<%--	<div class="ibox-title">
					<h5>类目管理</h5>
				</div>--%>
				<div class="ibox-content">
					<div class="row">
						<div class="col-sm-12 m-b-xs" style="margin-bottom: 15px; margin-top: 5px;">
							<a onclick="addColumn();" class="btn btn-success btn-outline"  ><i class="fa fa-file-text-o"></i> 创建类目</a>
						</div>
					</div>
					<table id="treeTable" class="table table-bordered table-hover table-responsive">
						<thead>
						<tr>
							<th>类目名称</th>
							<th>创建时间</th>
							<th colspan="2">操作</th>
						</tr>
						</thead>
						<tbody>
						<c:forEach items="${list}" var="tpl">
							<tr id="${tpl.id}" pId="${tpl.parent.id ne '1'?tpl.parent.id:'0'}">
								<td>
									${tpl.name}
								</td>
								<td><fmt:formatDate value="${tpl.createDate}" pattern="yyyy-MM-dd HH:mm"/></td>
								<td class="operation">
									<a class="btn btn-sm" onclick="update('${ctx}/cms/category/form?id=${tpl.id}');">修改</a>
									<a class="btn btn-sm demo3" data-param1="${ctx}/cms/category/delete?id=${tpl.id}">删除</a>
								</td>
							</tr>
						</c:forEach>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- 添加栏目 -->
<form:form id="inputForm" modelAttribute="category"  action="${ctx}/cms/category/save" method="post" class="form-horizontal">
	<div id="myModal" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
		<div class="modal-dialog">
			<div class="modal-body">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span>
						</button>
						<h4 class="modal-title">新增类目</h4>
					</div>
					<div class="modal-body">
						<%--<div class="form-group">
							<label class="col-sm-3 control-label">上级栏目：</label>
							<input type="hidden" name ="office.id" value="1">
							<input type="hidden" name="office.name" value="一级栏目">
							<div class="col-sm-8">
								<sys:treeselect id="category"  name="parent.id" value="${category.parent.id}" labelName="parent.name" labelValue="${category.parent.name}"
												title="栏目" url="/cms/category/treeData" extId="${category.id}" cssClass="form-control"/>
							</div>
						</div>--%>
						<div class="form-group">
							<label class="col-sm-3 control-label">类目名称：</label>
							<div class="col-sm-8">
								<input type="hidden" name ="office.id" value="1">
								<input type="hidden" name="office.name" value="一级栏目">
								<input type="hidden" id="id" name="id"/>
								<input type="hidden" id="category"  name="parent.id" value="${parentId}">
								<input type="text" id="name" name="name" class="form-control" required placeholder="请输入名称">
							</div>
						</div>
					</div>
					<div class="modal-footer">
						<center>
						<a class="btn btn-white"  onclick="cancelModel()">取消</a>
						<button class="btn btn-primary" style="margin-left: 30px;" type="submit">保存</button>
						</center>
					</div>
				</div>
			</div>
		</div>
	</div>
</form:form>
<script src="${ctxStatic}/js/plugins/validate/jquery.validate.min.js"></script>
<script src="${ctxStatic}/js/plugins/validate/messages_zh.min.js"></script>
<script src="${ctxStatic}/js/idenger.form.js"></script>

<script src="${ctxStatic}/js/plugins/sweetalert/sweetalert.min.js"></script>

<script type="text/javascript">
    function  addColumn() {
        $("#myModal").show();
    }
	function cancelModel() {
        $("#myModal").hide();
	}
</script>
<script>
    $(".demo3").click(function(){
        var param1=$(this).data("param1");//url
        prompt.confirm({
            title:"确定删除吗？",
            sure:function () {
                $.ajax({
                    url:param1,
                    success:function () {
                        prompt.info("删除成功");
                        setTimeout(function () {
                            window.location.reload();
                        },1000)
                    }
                })
            }
        });
    });

    function update(url) {
        $.ajax({
            url:url,
            success:function (res) {
                $("#name").val(res.data[0].category.name);
                $("#id").val(res.data[0].category.id);
                $("#category").val(res.data[0].category.parentId);
                $("#myModal").show();
            }
        })
    }


</script>
</body>
</html>